package com.atguigu.factory.simplefactory.pizzastore.order;

import com.atguigu.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.atguigu.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.atguigu.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.atguigu.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class OrderPizza {
    //构造器
    public OrderPizza(){
        System.out.println("订购披萨");
        Pizza pizza = null;
        String orderType;   //订购披萨的类型

        do{
            orderType = getType();
            if(orderType.equals("greek")){
                pizza = new GreekPizza();
            } else if (orderType.equals("cheese")) {
                pizza = new CheesePizza();
            } else if ("pepper".equals(orderType)) {
                pizza = new PepperPizza();
            } else{
                break;
            }
            pizza.setName(orderType);
            pizza.prepare();
            pizza.back();
            pizza.cut();
            pizza.box();
        }while (true);
    }

    //写一个方法，可以获取客户希望订购的披萨种类
    private String getType(){

        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类");
            String str = strin.readLine();
            return str;
        }catch (IOException e){
            e.printStackTrace();
            return "";
        }
    }
}
